package UnitTest;

import java.lang.reflect.Array;
import java.util.function.IntFunction;


/**
 * @Auther: Administrator
 * @Date: 2019/3/28/028 21 39
 * @Description:
 */


/**
 * 数组算法类
 */

public class ArrayAlg
{
    public static <T extends Comparable> T[] minmax(IntFunction<T[]> constr, T... a)
    {
        T[] mm = constr.apply(2);
        T min = a[0];
        T max = a[0];
        for (int i = 1; i < a.length; i++)
        {
            if (min.compareTo(a[i]) > 0) min = a[i];
            if (max.compareTo(a[i]) < 0) max = a[i];

        }
        mm[0]=min;
        mm[1]=max;
        return mm;
    }

    public static <T extends Comparable> T[] minmax(T... a)
    {
        T[] mm = (T[]) Array.newInstance(a.getClass().getComponentType(), 2);
        T min = a[0];
        T max = a[0];
        for (int i = 1; i < a


                .length; i++)
        {
            if (min.compareTo(a[i]) > 0) min = a[i];
            if (max.compareTo(a[i]) < 0) max = a[i];
        }
        mm[0]=min;
        mm[1]=max;
        return (T[]) mm; // compiles with warning
    }

    public static void main(String[] args) {
        int a = 3;
        int b = 1;
        System.out.println(a<<1);
        System.out.println(~a & b);
    }

}
